package com.yc.txx.servlet;

import com.github.pagehelper.PageHelper;
import com.google.gson.Gson;
import com.yc.txx.entity.Car;
import com.yc.txx.mapper.CarMapper;
import com.yc.txx.util.MyBatisHelper;
import org.apache.ibatis.session.SqlSession;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Map;

@WebServlet("/QueryBrand.s")
public class QueryBrandServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
        resp.setContentType("application/json;charset=UTF-8");


        SqlSession session = MyBatisHelper.getSession();
        CarMapper mapper = session.getMapper(CarMapper.class);
        List<Map> maps = mapper.selectBrands();

        String json = new Gson().toJson(maps);
        resp.getWriter().append(json);
    }


}
